package com.example.music08.utils;

import android.content.Context;
import android.content.SharedPreferences;

//sharedpreferences工具类
public class SpUtils {
    private SharedPreferences sp;
    //单例懒汉
    private SpUtils(Context context){
        sp = context.getSharedPreferences("2208",Context.MODE_PRIVATE);
    }
    private static SpUtils spUtils;
    public static SpUtils getInstance(Context context){
        if(spUtils==null){
            spUtils = new SpUtils(context);
        }
        return spUtils;
    }
    //记录播放顺序--int
    public void putInt(String key,int value){
        sp.edit().putInt(key,value).commit();
    }
    //获取播放记录
    public int getInt(String key){
        return sp.getInt(key,0);
    }

    //保存个人信息
    public void putString(String key,String value){
        sp.edit().putString(key,value);
    }
    //读取个人信息
    public String getString(String key){
        return sp.getString(key,"");
    }
}
